package src.算法.冒泡排序;

public class SoakSort {

    public static void sort(Comparable[] a){
        for (int i = a.length-1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if(greater(a[j],a[j+1])){
                    exch(a,j,j+1);
                }
            }
        }
    }
    // 比较前一个元素是否大于后一个元素
    private static boolean greater(Comparable a,Comparable b){
        int result = a.compareTo(b);
        return result>0;
    }
    // 数组元素i和j交换位置
    private static void exch(Comparable[] a,int i,int j){
        Comparable temp;
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
